<%@ page import="org.apache.lucene.analysis.standard.StandardAnalyzer" %>
<%@ page import="org.apache.lucene.document.Document" %>
<%@ page import="org.apache.lucene.queryParser.ParseException" %>
<%@ page import="org.apache.lucene.queryParser.QueryParser" %>
<%@ page import="org.apache.lucene.search.Hits" %>
<%@ page import="org.apache.lucene.search.IndexSearcher" %>
<%@ page import="org.apache.lucene.search.Query" %>
<%@ page import="org.apache.lucene.store.Directory" %>
<%@ page import="org.apache.lucene.store.FSDirectory" %>
<%@ page import="java.util.logging.Logger" %>
<%@ page language="java" %>
<%@ taglib uri="/provisioning-taglib.tld" prefix="provisioning" %>
<%
    Logger logger = Logger.getAnonymousLogger();

    Directory directory = FSDirectory.getDirectory(System.getProperty("java.io.tmpdir") + "/index", false);
    IndexSearcher indexSearcher = new IndexSearcher(directory);
    String param = request.getParameter("searchParam");
    logger.info("JV: Search Parameter = " + param);

    Query query = null;
    try {
        QueryParser parser = new QueryParser("description", new StandardAnalyzer());
        query = parser.parse(param);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    Hits hits = indexSearcher.search(query);
    logger.info("Hits = " + hits.length());

%>
<p>
    <a href="index.html">Home</a> |
    <a href="ParStocker.html">Stock PAR Files</a> |
    <a href="search-catalog.html">Search Catalog</a> |
    <a href="display-catalog">View Catalog</a>
</p>
<hr/>

<form action="CatalogSearcher.jsp" method="post">
    <input size="40" name="searchParam"/> <input type="submit" value="Search"/>
</form>

<table border="1'">
    <thead>
        <tr bgcolor="#00FF00">
            <th>Display Name</th>
            <th>Version</th>
            <th>Vendor</th>
            <th>Descripton</th>
            <th>Icon</th>
        </tr>
    </thead>
    <%
        for (int i = 0; i < hits.length(); i++) {
            Document document = hits.doc(i);
            String bundleId = document.getField("id").stringValue();
            logger.info("Bundle ID = " + bundleId);
    %>
    <provisioning:bundle-descriptor bundleId="<%=bundleId%>">
        <tr>
            <td>
                <a href="AdapterController?bundleId=<%=bundleId%>">
                    <provisioning:display-name locale=""/></a>
            </td>

            <td align="center"><provisioning:version/></td>
            <td>

                <provisioning:vendor-name locale=""/><br/>
            </td>
            <td>
                <provisioning:description locale=""/><br/>
            </td>
            <td>
                <provisioning:icons locale="">
                    <provisioning:icon width="80" height="80"/>
                </provisioning:icons>
            </td>
        </tr>
    </provisioning:bundle-descriptor>
    <%

        }
        directory.close();
        indexSearcher.close();
    %>
</table>